home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 September (IDG) / Sep99.iso / Shareware World / Comms & Internet / LinkConverter 1.1.2 / Dialog Director v0.7 / Examples / SuperCT2.as < prev    next >
Encoding:
Text File  |  1998-01-30  |  3.6 KB  |  97 lines  |  [TEXT/ToyS]

  1. property desc : "Drop one or more files on my application icon to change their creators and/or types.
  2.  
  3. Copyright © 1996-1998 Christopher E. Hyde.
  4. All rights reserved.
  5. Email: drjekyll@hylight.demon.co.uk"
  6. property txt : "TEXT"
  7. property appList : ["MPW", "ToolServer", "SPM", "BBEdit", "CodeWarrior", "Simple Text", "Claris Works", "MS Word", "Other:", ¬
  8.     "Script Editor", "Script Debug’r", "Scripter", "Navigator", "ResEdit"] -- Append up to 4 more application/creator/types
  9. property cList : ["MPS ", "MPSX", "SPM ", "R*ch", "CWIE", "ttxt", "BOBO", "MSWD", null, "ToyS", "asDB", "MEme", "MOSS", "RSED", 15, 16, 17, 18]
  10. property tList : [txt, txt, txt, txt, txt, txt, txt, txt, null, txt, txt, txt, txt, "rsrc"]
  11. property opt : 6
  12. property doCreat : true
  13. property doType : true
  14. property dlogBounds : null
  15.  
  16. global fileList
  17. open []
  18.  
  19. on open aFileList
  20.     if (dd count dialogs) = 0 then
  21.         DoDialog(aFileList)
  22.     else
  23.         SetFiles(fileList & aFileList)
  24.     end if
  25. end open
  26.  
  27. on DoDialog(aFileList)
  28.     SetFiles(aFileList)
  29.     try
  30.         repeat
  31.             set i to dd interact with user
  32.             if i = 3 then
  33.                 DoChange()
  34.                 SetFiles([])
  35.             else if i = 4 then
  36.                 SetFiles([])
  37.             else if i = -1 then
  38.                 set [opt, _, _, doCreat, doType] to dd get value of items 5 thru 9 of dialog 1
  39.                 set dlogBounds to dd get bounds of dialog 1
  40.                 exit repeat
  41.             end if
  42.         end repeat
  43.     on error (*m number n from f to T partial result p
  44.         dd uninstall
  45.         display dialog m & " Code = " & n
  46.         error m number n from f to T partial result p*)
  47.     end try
  48.     dd uninstall
  49. end DoDialog
  50.  
  51. on SetFiles(aFileList)
  52.     set fileList to aFileList
  53.     if (dd count dialogs) = 0 then
  54.         dd install with fonts [null, null, null, null, {name:"Geneva", size:9}] with grayscale
  55.         if dlogBounds = null then set dlogBounds to dd calc dialog bounds [260, 330]
  56.         dd make dialog {bounds:dlogBounds, name:"Set File Creator & Type", style:standard window, closeable:true, contents:[¬
  57.             {class:dummy, enabled:false}, ¬
  58.             {class:dummy, enabled:[dOr, 8, 9]}, ¬
  59.             {class:push button, bounds:[190, 300, 250, 320], name:"Change", enabled:[dAnd, 1, 2]}, ¬
  60.             {class:push button, bounds:[10, 300, 90, 320], name:"Clear Files", enabled:1}, ¬
  61.             {class:radio group, bounds:[10, 60, 120, 76], button offset:[120, 20], max down:9, value:opt, contents:appList}, ¬
  62.             {class:text field, name:"Creator", name bounds:[30, 240, 85, 256], bounds:[90, 240, 140, 256], enabled:[dAnd, 5 + 9 * 256, 8]}, ¬
  63.             {class:text field, name:"Type", name bounds:[155, 240, 190, 256], bounds:[195, 240, 245, 256], enabled:[dAnd, 5 + 9 * 256, 9]}, ¬
  64.             {class:check box, bounds:[30, 265, 140, 281], name:"Set Creator", value:doCreat}, ¬
  65.             {class:check box, bounds:[155, 265, 260, 281], name:"Set Type", value:doType}, ¬
  66.             {class:group box, bounds:[8, 8, 252, 40], style:secondary group}, ¬
  67.             {class:static text, bounds:[12, 12, 248, 36], font:5, contents:""} ¬
  68.                 ]}
  69.     end if
  70.     set n to fileList's length
  71.     dd set enabled of item 1 of dialog 1 to n ≠ 0
  72.     if n ≠ 0 then
  73.         dd set contents of item 11 of dialog 1 to "Change the file creators and/or types of the " & n & " files that were dropped on me."
  74.         set f to info for (fileList's item 1)
  75.         dd set value of items 6 thru 7 of dialog 1 to [f's file creator, f's file type]
  76.     else
  77.         dd set contents of item 11 of dialog 1 to desc
  78.     end if
  79. end SetFiles
  80.  
  81. on DoChange()
  82.     try
  83.         set [opt, c, T, doCreat, doType] to dd get value of items 5 thru 9 of dialog 1
  84.         if opt ≠ 9 then
  85.             set c to item opt of cList
  86.             set T to item opt of tList
  87.         end if
  88.         tell application "Finder"
  89.             repeat with f in fileList
  90.                 if doCreat then set creator type of f to c
  91.                 if doType then set file type of f to T
  92.             end repeat
  93.         end tell
  94.     on error
  95.         beep
  96.     end try
  97. end DoChange